<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>jquery template demo</title>
  </head>

  <body>
    <!-- 2、骨架结构 -->
    <table cellspacing="0" cellpadding="3" border="1">
      <tbody id="rows"></tbody>
    </table>

    <!-- 3、定义模板（注意type类型） -->
    <script id="myTemplate" type="text/x-jquery-tmpl">
      <tr>
        <td>${id}</td>
        <td>${name}</td>
      </tr>
    </script>

    <!-- 1、引入文件 -->
    <script
      type="text/javascript"
      src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js"
    ></script>
    <script type="text/javascript" src="./9/jquery.tmpl.min.js"></script>
    <!-- 4、将数据渲染到模板； -->
    <script>
      $(function () {
        // tip: 这里请求需要启本地 node 服务
        // url: http://192.168.1.126:8088/9/jquery_gitkeep/plugins/jquery.tmpl/demo/2.html
        $.ajax({
          url: '/9/jquery_gitkeep/plugins/jquery.tmpl/demo/data/2.json',
          type: 'GET',
          success: function (res) {
            console.log(res)
            if (res.code === 0) {
              $('#myTemplate').tmpl(res.data).appendTo('#rows')
            }
          },
        })
      })
    </script>
  </body>
</html>
